package com.jt.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jt.pojo.Item;
import com.jt.pojo.ItemDesc;
import com.jt.service.DubboItemService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ItemController {

    //启动时是否校验有服务提供者
    @Reference(check=false)
    private DubboItemService itemService;

    /**
     * 根据商品ID查询商品信息
     * 1.URL地址:http://www.jt.com/items/562379.html
     * 2.参数:   562379 restFul风格
     * 3.返回值: String
     * 4.页面取值操作
     *      ${item.title }          获取商品信息   同步取值
     *      ${itemDesc.itemDesc }   获取商品详情信息
     */
    @RequestMapping("/items/{itemId}")
    public String findItemById(@PathVariable Long itemId, Model model){
        //1.获取商品相关信息
        Item item = itemService.findItemById(itemId);
        ItemDesc itemDesc = itemService.findItemDescById(itemId);

        //2.将数据传递到页面中
        model.addAttribute("item",item);
        model.addAttribute("itemDesc",itemDesc);

        //跳转到商品展现页面
        return "item";
    }

}
